package gpl.androidcommons.scotlandyard.adapter;

import gpl.androidcommons.R;
import gpl.androidcommons.scotlandyard.ui.SYColors;
import gpl.scotlandyard.beans.basics.Player;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PlayerTicketsAdapter extends BaseAdapter {

  private final Player player;
  private final LayoutInflater inflater;

  public PlayerTicketsAdapter(Player player, LayoutInflater inflater) {
    this.player = player;
    this.inflater = inflater;
  }

  @Override
  public int getCount() {
    return player.isFugitive() ? 5 : 3;
  }

  @Override
  public Object getItem(int position) {
    return position;
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    TextView textView = (TextView) inflater.inflate(R.layout.text_view_rounded, null);
    GradientDrawable bgShape = (GradientDrawable) textView.getBackground();
    switch (position) {
      case 0:
        bgShape.setColor(SYColors.RED.getRgbColor());
        textView.setText(player.getUg() + "");
        break;
      case 1:
        bgShape.setColor(SYColors.GREEN.getRgbColor());
        textView.setText(player.getBus() + "");
        break;
      case 2:
        bgShape.setColor(SYColors.YELLOW.getRgbColor());
        textView.setText(player.getTaxi() + "");
        break;
      case 3:
        bgShape.setColor(SYColors.BLACK.getRgbColor());
        textView.setTextColor(Color.WHITE);
        textView.setText(player.getHide() + "");
        break;
      case 4:
        bgShape.setColor(SYColors.ORANGE.getRgbColor());
        textView.setTextColor(SYColors.WHITE.getRgbColor());
        textView.setText(player.getTwice() + "");
        break;
      default:
        break;
    }

    return textView;
  }
}
